<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Zenika-Formation Wicket - zenContact</title>
<link id="stylesheet" href="zencontact.css" rel="stylesheet"
	type="text/css" />
<script language="Javascript" type="text/javascript" src="prototype.js"></script>
<script language="Javascript" type="text/javascript">

function deleteContact(id){
	deleteRow(id);
	var params="id="+id;
	new Ajax.Request('deleteContact.jsp',
		{
			method: 'post', 
			parameters: params
		}
	
	);
	
}

function AddOneRow(paramName,paramFirstName,id){
			
	var TR =  document.getElementById('contactsTable').insertRow( -1 );
	TR.setAttribute("id",""+id+"");
	var TD = TR.insertCell( -1 );
	var text = "<b><span id=\"lastName\">"+paramName+"</span><span id=\"firstName\">"+paramFirstName+"</span></b>";
	TD.innerHTML = text;
	var TD = TR.insertCell( -1 );
	var text = "<a id=\"edit\" href=\"EditContactPageFW.html?edit=1&id="+id+"\"><message key=\"link.edit\">Edit</message></a> | <a id=\"delete\" href=\"javascript:deleteContact("+id+");\"><message key=\"link.delete\">Delete</message></a>";
	TD.setAttribute("align","right");
	TD.setAttribute("class","actionLink");
	TD.innerHTML = text;

}

function deleteRow(id){
	var lignes =  document.getElementById('contactsTable').getElementsByTagName('tr');
	var index=0;
	for (var i=0;i<lignes.length;i++){
		if(parseInt(lignes[i].getAttribute('id')) == id){
			index = i;
		}
	}

	document.getElementById('contactsTable').deleteRow(index);
}

function showListContact(){
	new Ajax.Request('contacts.jsp',
		{
			method: 'get', 
			onSuccess: function(transport){
				var contactTags = transport.responseXML.getElementsByTagName('contact');
				
				for(var i=0; i<contactTags.length ;i++){
					id = parseInt(contactTags[i].getAttribute("id"));
					name = contactTags[i].getAttribute("lastname");
					firstname = contactTags[i].getAttribute("firstname");
					AddOneRow(name,firstname,id);
				}
			
			}
		}
	
	);
}

</script>
</head>
<body onLoad="showListContact()">

<div id="menuPanel">

<panel>
<div id="menu">
	<ul>
		<li><a href="#" id="linkHome"><span id="homeLinkLabel"></span> </a></li>
		<li><a href="#" id="linkAbout"><span id="aboutLinkLabel"></span></a></li>
		<li><select id="localeSelect"></select></li>
	</ul>
</div>
</panel>

</div>

<div id="header">
<h1>zenContact</h1>
<h2>&nbsp;Formation Wicket</h2>
</div>

<div id="content">
<div id="contacts">
<span id="searchPanel">

<panel>
	<form id="searchForm">
	<table cellspacing="3" cellpadding="3">
		<tr>
			<td><message key="label.search">Contact name</message>
			:</td>
			<td><input id="searchString" type="text" name="search" /></td>
			<td><input type="submit" value="Search" class="button"
				id="searchButton"></td>
			<td class="actionLink"><a id="addContact" href="EditContactPageFW.html?edit=0"><message
				key="label.new">Add new Contact</message></a></td>
		</tr>
	</table>
	</form>
</panel>

</span>
<h2 class="title" id="title">Edit / Delete</h2>
<child />
</div>

<div id="contacts">
<div class="contact">
<table cellspacing="5" id="contactsTable">
</table>
</div>
</div>
</div>

<div id="footer">
<p id="legal"><a href="http://www.zenika.com/">Zenika</a> Copyright
&copy; 2008</p>
</div>

</body>
</html>